package com.ggh.handler;
import com.ggh.entity.RoomBeanP;

/*
		* 创建房间
		* */
public class CreateRoomP {


	public static synchronized RoomBeanP foundRoom(RoomBeanP room) {
		while (true) {
			// 房间号，6位数
			String roomno="6";
			// 产生随随机数：房间号码
			for (int i = 0; i < 5; i++) {
				int a = (int) (Math.random() * 10);
				roomno += a;
			}
			// 判断房间号是否存在与房间池中
			if (Public_State_P.roomMap.get(roomno) != null) {
				continue;
			} else if (room.getGame_type()<2){
				// 初始化房间信息
				room.Initialization();
				room.setRoomno(roomno);
				//加入房间线程
				Public_State_P.roomMap.put(roomno, room);
				return room;
			}
			//四人房间
			if (Public_State_PSiRen.roomMap.get(roomno) != null){
				continue;
			}else if (room.getGame_type()>2){
				room.Initialization();
				// 存入房间
				room.setRoomno(roomno);
				// 房间存入线程map中
				Public_State_PSiRen.roomMap.put(roomno, room);
				return room;
			}
		}
	}
}
